package com.chinacoal.microservice.controller;

import com.chinacoal.microservice.WechatClient;
import com.chinacoal.microservice.service.WechatService;
import com.chinacoal.microservice.util.Result;
import com.chinacoal.microservice.util.UserLoginToken;
import com.chinacoal.microservice.util.WeixinCheckoutUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;



/**
 * @author zhuliang
 * @version V1.0
 * @Description: 微信-后端控制类
 * @date 2020-12-21 10:04
 */
@RestController
public class WechatController implements WechatClient {

    @Autowired
    private WechatService wechatService;

    /**
     * @Description: 用户名，密码登录
     * @author zhuliang
     * @date 2020/12/21 18:17
     */
    @Override
    public Result<String> usernamePasswordLogin(String userName, String passWord) {
        return wechatService.usernamePasswordLogin(userName, passWord);
    }

    /**
     * @Description: 发送验证码
     * @author zhuliang
     * @date 2020/12/22 9:42
     */
    @Override
    public Result verificationCode(String phoneNumber, Integer type) {
        return wechatService.verificationCode(phoneNumber, type);
    }

    /**
     * @Description: 验证码登录
     * @author zhuliang
     * @date 2020/12/22 13:54
     */
    @Override
    public Result<String> verificationCodeLogin(String phoneNumber, int verificationCode) {
        return wechatService.verificationCodeLogin(phoneNumber, verificationCode);
    }

    /**
     * @Description: 获得openId
     * @author zhuliang
     * @date 2020/12/24 17:16
     */
    @Override
    @UserLoginToken
    public Result getOpenId(String code, String token) {
        return wechatService.getOpenId(code, token);
    }

    /**
     * @Description: 添加用户的openId
     * @author zhuliang
     * @date 2021/2/2 11:05
     */
    @Override
    @UserLoginToken
    public Result addOpenId(String openId, String token) {
        return wechatService.addOpenId(openId, token);
    }
}
